﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MVC.Models;
using MVC.Models.Database;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace MVC.Controllers
{
    public class ManageUsersController : Controller
    {
        private readonly LifengContext _context;
        public ManageUsersController(LifengContext context)
        {
            _context = context;
        }
        [Route("/ManageUsers")]
        public IActionResult ManageUsers()
        {
            var users = _context.Users.ToList();
            ViewData["User"] = users;
            return View();
        }
        //删除
        [Route("/Dele/{id}")]
        public IActionResult Dele(int id) 
        {
            Console.WriteLine(id);
            //值传不出来
            var user = _context.Users.FirstOrDefault(a => a.UserId == id);
            //值为空
            if (user == null)
            {
                return Content("为空");
            }
            _context.Users.Remove(user);
            var row = _context.SaveChanges();
            ViewData["User"] = user;
            return new JsonResult(new { code = 200, msg = "删除成功" });
        }


        
    }
}
